
;input: seeds - instances for which we want to find the k nearest neighbours (m x ns
;	data - the dataset to search (m x nd
;	k - kay!
;return is a k x n array, containing the attribute value of each of the k neighbours for each seed instance
function knearestneighbour, seeds, data, k
	sz = size(seeds, /dimensions)

	dist = reform( euclidean_distances(data, seeds, raw_dist=raw_dist) )
	; (nd x ns) distance metric for each seed to each data instance

	return_me = ulonarr(k,sz[1])

	;for each seed, sort neighbour list, take 0 to kth elements, must return indices into data[x,*] array
	for i=0, sz[1] - 1 do begin
		return_me[*,i] = (sort(dist[*,i]))[0:k-1]
	endfor
	return, return_me
end